/*
  Synopsis of a qcd binary data format
  =======================================

  Binary data file layout
  -----------------------
   UNI_header
  [IOsite_order_list] (parallel IO)
   binary data
  [binary data
   ...
  ]

  All meta-data will be written to a .info file.
  The meta-data format is:
  keyword value

  e.g. a quark propagator 
  project.url			"http://project/info.html"
  header.timestamp		"Wed Feb  9 09:17:14 UTC 2000"
  header.size-of-element	4 (float)
  header.elements-per-site	24 (spinor)
  header.dim[0]			8
  header.dim[1]			8
  header.dim[2]			8
  header.dim[3]			16
  header.site-order		1 (parallel ordering)
  gauge.url			"http://project/gauge/001000.html"
  gauge.sweeps			1000
  quark.kappa			0.120
  quark.spin-color[0]		0,0
  quark.spin-color[1]		0,1
  quark.spin-color[2]		0,2
  file.CRC			3519867437

Checksums may be computed and added to the .info file with a tool based
upon the gnu cksum program.

  the gauge meta-data url points to the gauge info:
  project.url			"http://project/info.html"
  header.timestamp		"Mon Feb  7 12:42:54 UTC 2000"
  header.size-of-element	4 (float)
  header.elements-per-site	72 ( 4 * SU(3) )
  header.dim[0]			8
  header.dim[1]			8
  header.dim[2]			8
  header.dim[3]			16
  header.site-order		0 (serial)
  gauge.sweeps			1000
  gauge.beta[0]			5.7
  gauge.beta[1]			5.47
  gauge.beta[2]			5.2
  gauge.mq[0]			0.010
  gauge.mq[1]			0.035
  file.CRC			1813378857
*/

#ifdef __cplusplus
extern "C" {
#endif 
#ifndef __IO_UNI_H__
#define __IO_UNI_H__

#include <io_common.h>

#define IO_UNI_MAGIC 0x71626434 /* "qbd4" */

typedef struct {
  IO_type32 magic_number;
  IO_type32 gmtime;
  IO_type32 size_of_element;
  IO_type32 elements_per_site;
  IO_type32 dim[4];
  IO_type32 site_order;
} IO_uni_header;

void IO_set_header_for_write ( IO_filehand* fh, IO_uni_header* header,
			       int size_of_element,
			       int elements_per_site, int* dim, int order );

int IO_write_header ( IO_filehand* fh, IO_uni_header* header );

int IO_write_site_data ( IO_filehand* fh, IO_uni_header* header,
			 int nsites, void* site_data );

int IO_read_header ( IO_filehand* fh, IO_uni_header* header );

void IO_print_header ( FILE *out, IO_uni_header* header );

int IO_read_site_data ( IO_filehand* fh, IO_uni_header* header,
			 int nsites, void* site_data );

int IO_number_of_records ( IO_filehand* fh, IO_uni_header* header );

#endif
#ifdef __cplusplus
}
#endif 
